package com.javabi.unix.parser.ps;

import java.util.List;

public class PsRow {

	public static final String USER = "USER";
	public static final String PID = "PID";
	public static final String CPU = "%CPU";
	public static final String MEM = "%MEM";
	public static final String VSZ = "VSZ";
	public static final String RSS = "RSS";
	public static final String TTY = "TTY";
	public static final String STAT = "STAT";
	public static final String START = "START";
	public static final String TIME = "TIME";
	public static final String COMMAND = "COMMAND";

	private final PsColumnSet columnSet;
	private final List<String> row;

	public PsRow(PsColumnSet columnSet, List<String> row) {
		if (columnSet.isEmpty()) {
			throw new NullPointerException("columnSet");
		}
		if (row.isEmpty()) {
			throw new IllegalArgumentException("row is empty");
		}
		this.columnSet = columnSet;
		this.row = row;
	}

	public PsColumnSet getColumnSet() {
		return columnSet;
	}

	public boolean contains(String column) {
		return columnSet.contains(column);
	}

	public String get(String column) {
		int index = columnSet.indexOf(column);
		return row.get(index);
	}

	public int getInt(String column) {
		String value = get(column);
		return Integer.parseInt(value);
	}

	public long getLong(String column) {
		String value = get(column);
		return Long.parseLong(value);
	}

	public float getFloat(String column) {
		String value = get(column);
		return Float.parseFloat(value);
	}

	public double getDouble(String column) {
		String value = get(column);
		return Double.parseDouble(value);
	}

	@Override
	public String toString() {
		return "PsRow" + row;
	}

}
